import os

def generate_tree(root, prefix="", is_last=True, exclude=None):
    exclude = exclude or []
    files = sorted(
        [f for f in os.listdir(root) if f not in exclude and not f.startswith('.')],
        key=lambda x: os.path.isdir(os.path.join(root, x)),
        reverse=True
    )
    for i, file in enumerate(files):
        path = os.path.join(root, file)
        is_dir = os.path.isdir(path)
        connector = "└── " if i == len(files) - 1 else "├── "
        print(f"{prefix}{connector}{file}")
        if is_dir:
            new_prefix = prefix + ("    " if i == len(files) - 1 else "│   ")
            generate_tree(path, new_prefix, i == len(files) - 1, exclude=exclude)

# 使用示例
generate_tree(".", exclude=["__pycache__"])